import UIKit
import MJRefresh

extension UIScrollView {
    
    func addRefreshHeaderCallback(_ callback: @escaping () -> Void) {
        let header = MJRefreshNormalHeader(refreshingBlock: callback)
        header.stateLabel?.isHidden = true
        self.mj_header = header
    }
    
    func addRefreshFooterCallback(_ callback: @escaping () -> Void) {
        let footer = MJRefreshBackNormalFooter(refreshingBlock: callback)
        footer.setTitle("", for: .refreshing)
        footer.setTitle("", for: .idle)
        footer.setTitle("", for: .willRefresh)
        footer.setTitle("", for: .pulling)
        footer.setTitle("已经到底了，没有更多了", for: .noMoreData)
//        footer.arrowView?.image = UIImage()
        footer.labelLeftInset = 0
        footer.ignoredScrollViewContentInsetBottom = iPhoneX ? 34:0
        self.mj_footer = footer
    }
    /// header - 开始刷新数据
    func headerBeginRefreshing() {
        self.mj_header?.beginRefreshing()
    }
    /// header - 结束刷新数据
    func headerEndRefreshing() {
        self.mj_header?.endRefreshing()
        
        AppThemeManager.shared.playSystemSound(forResource: "tab_voice.mp3")
        
    }
    /// footer - 开始加载数据
    func footerBeginRefreshing() {
        self.mj_footer?.beginRefreshing()
    }
    /// footer - 结束加载数据
    func footerEndRefreshing() {
        self.mj_footer?.endRefreshing()
    }
    /// footer - 开始加载数据
    func footerEndRefreshingWithNoMoreData() {
        self.mj_footer?.endRefreshingWithNoMoreData()
    }
    /// footer - 结束加载数据
    func footerResetNoMoreData() {
        self.mj_footer?.resetNoMoreData()
    }
}
